<?php

// @formatter:off
/**
 * @file info.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-06-03 03:40:32 +0000 (Tue, 03 Jun 2014) $
 *
 * $Id: info.php 112 2014-06-03 03:40:32Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/services/site/info.php $
 */
// @formatter:on
//
//global $wcPaths;
//require_once $wcPaths["mvc"]["config"];

class WCServiceSiteInfo extends WCService {
	//
	// Class methods.
	public function __construct() {
		parent::__construct();

		$this->_useCache = true;
	}
	//
	// Protected methods.
	protected function runGET() {
		global $wcVersions;
		global $wcSite;
		global $wcMVCConfig;
		global $wcDefaults;
		global $wcProfile;
		global $wcUser;

		$this->_results = array();

		$buildUser = ($wcUser && $wcUser->ok());

		//
		//
		// @{
		$this->_results["wcomix"] = array();
		$this->_results["wcomix"]["name"] = $wcVersions["name"];
		$this->_results["wcomix"]["version"] = $wcVersions["version"];
		// @}
		//
		//
		// @{
		$this->_results["site"] = array();
		$this->_results["site"]["name"] = $wcSite["name"];
		$this->_results["site"]["email"] = $wcSite["email"];
		if($wcSite["wiki"]) {
			$this->_results["site"]["wiki"] = $wcSite["wiki"];
		}
		// @}
		//
		//
		// @{
		if(isset($wcMVCConfig)) {
			$this->_results["skin"] = array();
			$this->_results["skin"]["web"] = $wcMVCConfig["skin"];
			$this->_results["skin"]["mobile"] = $wcMVCConfig["skin-mobile"];
		}
		// @}
		//
		//
		// @{
		$this->_results["readonly"] = $wcDefaults["read-only"];
		// @}
		//
		// Groups.
		// @{
		$this->_results["groups"] = array(
			"public" => array(),
			"private" => array(),
			"user" => array()
		);
		foreach(WCGroupsHolder::I()->items() as $group) {
			if(!is_dir($group->root())) {
				continue;
			}

			$info = array(
				"id" => $group->id(),
				"name" => $group->name()
			);

			$this->_results["groups"][$group->isPublic() ? "public" : "private"][] = $info;
			if($buildUser && $wcProfile->grantedGroup($group)) {
				$info["as"] = $wcUser->profileCode($group);
				$this->_results["groups"]["user"][] = $info;
			}
		}
		// @}
		//
		// Groups.
		// @{
		if($buildUser) {
			$this->_results["user"] = array(
				"id" => $wcUser->id(),
				"name" => $wcUser->name()
			);
		}
		// @}

		$this->_count = 1;
	}
}
